package com.cdtu.labpreview.controller;

import com.cdtu.labpreview.common.Result;
import com.cdtu.labpreview.common.UserHolder;
import com.cdtu.labpreview.dto.UserDTO;
import com.cdtu.labpreview.entity.InstrumentIntroduction;
import com.cdtu.labpreview.entity.PictureDisplay;
import com.cdtu.labpreview.service.IPictureDisplayService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 实验图片展示模块
 */
@RestController
@RequestMapping("/picture")
@Api(tags = "实验图片展示模块")
public class PictureDisplayController {

    @Autowired
    private IPictureDisplayService pictureDisplayService;

    /**
     * 查看实验图片展示（老师、学生）
     * @return
     */
    @GetMapping
    public Result getPictureDisplay(){
        UserDTO userDTO = UserHolder.getUser();
        int no = userDTO.getUserNo();
        int type = userDTO.getType();
        return pictureDisplayService.getPictureDisplay(no,type);
    }

    /**
     * 添加实验图片展示（老师）
     * @param pictureDisplay
     * @return
     */
    @PostMapping
    public Result addPictureDisplay(@RequestBody PictureDisplay pictureDisplay){
        pictureDisplay.setTno(UserHolder.getUser().getUserNo());
        return pictureDisplayService.addPictureDisplay(pictureDisplay);
    }

    /**
     * 修改实验图片展示（老师）
     * @param pictureDisplay
     * @return
     */
    @PutMapping
    public Result updatePictureDisplay(@RequestBody PictureDisplay pictureDisplay){
        return pictureDisplayService.updatePictureDisplay(pictureDisplay);
    }

    /**
     * 删除实验图片展示（老师）
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deletePictureDisplay(@PathVariable("id") long id){
        return pictureDisplayService.deletePictureDisplay(id);
    }
}
